package Interface;

import org.junit.Test;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * Predicate<T>断定型接口
 * boolean test(T,t);
 */
public class TestPredicate {
    @Test
    public void test() {
        List<String> list = Arrays.asList("HEllo", "hallo", "www", "https");
        filterStr(list, (s) -> s.length() > 3).forEach(System.out::println);

    }

    //需求：将满足条件字符串 添加到集合中
    public List<String> filterStr(List<String> strs, Predicate<String> pre) {
        List<String> list = new ArrayList<>();
        for (String str : strs
        ) {
            if (pre.test(str)) {
                list.add(str);
            }
        }
        return list;
    }
}
